<template>
	<view class="main">
		<uni-nav-bar fixed left-icon="back" title="充值" right-text="充值记录" color="#333333" backgroundColor="#FFFFFF" :border="false" statusBar
			@clickLeft="goReturn" @clickRight="go"></uni-nav-bar>
		  <view class="td-title">充值金额</view>
		  <view class="td-num">
			  <view class="left">
				  ￥
			  </view>
			  <view class="right">
				  {{formData.money}}
			  </view>
		  </view>
		   <view class="td-pays">
			   <view class="pay-item" v-for="(item,index) in items" :key="index" @click="choose(item)">
				   <view class="left">
					   <image :src="item.icon" mode="aspectFit"></image>
					   <view class="pay-name">{{item.title}}</view>
				   </view>
				   <view class="right">
					   <uni-icons v-if="formData.paytype == item.pay_type" type="checkbox-filled" size="18" color="#2A7BFF"></uni-icons>
						<view v-else class="circle"></view>
				   </view>
			   </view>
		   </view>
		 <mono-keyboard :show="show" @change="change" @confirm="submit" btnColor="#2A7BFF"></mono-keyboard>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				 show:true,
				 formData:{
					 money:'',
					 paytype:''
				 },
				 items:[]
			}
		},
		onLoad() {
			this.getPays()
		},
		methods: {
			// hideKeybord(){
			// 	console.log('======123=========12===')
			// 	uni.hideKeyboard()
			// },
			getPays(){
				this.$http.get('/v1/get_pay_list',res => {
					this.items = res.data
					this.items.forEach(item => {
						item.icon = this.$global.imgUrl + item.icon
					})
				})
			},
			choose(item){
				this.formData.paytype = item.pay_type
			},
			change(val){
				this.formData.money = val
			},
			submit(val){
				if(!this.formData.paytype){
					uni.showToast({
						icon:'none',
						title:'请选择支付类型'
					})
					return
				}
				if(this.formData.paytype == 5){
					uni.switchTab({
						url:'../../kefu/kefu'
					})
					return
				}
				let para = {
					pay_type: this.formData.paytype,
					money:this.formData.money
				}
				this.$http.post('/v1/recharge',para,res => {
					if(res.code == 200){
						uni.setStorageSync('payUrl',res.data.payUrl);
						uni.navigateTo({
							url:'cashpay/cashpay'
						})
					}
				})
			},
			 go(){
				uni.navigateTo({
					url:'cashinrecord/cashinrecord'
				}) 
			 },
			// 返回
			goReturn() {
				uni.navigateBack({
					delta: 1
				});
			}
		}
	}
</script>

<style lang="scss">
	 .td-title{
		 font-size: 28upx;
		 margin-top: 80upx;
	 }
	 .td-num{
		 height: 140upx;
		 line-height: 140upx;
		 display: flex;
		 align-items: center;
		 border-bottom: 1px solid #F8F8F8;
		 .left{
			 font-size: 48upx;
		 }
		 .right{
			 font-size: 72upx;
			 margin-left: 20upx;
		 }
	 }
	 .td-pays{
		 display: flex;
		 flex-direction: column;
		 .pay-item{
			 display: flex;
			 justify-content: space-between;
			 height: 100upx;
			 align-items: center;
			 border-bottom: 1px solid #F8F8F8;
			 .left{
				 display: flex;
				 justify-content: left;
				 image{
					 width: 44upx;
					 height: 44upx;
				 }
				 .pay-name{
					 font-size: 28upx;
					 color: #333333;
					 margin-left: 20upx;
				 }
			 }
			 .right{
				 
				 display: flex;
				 align-items: center;
				 .circle{
					 height: 24upx;
					 width: 24upx;
					 border: 1px solid #999999;
					 border-radius: 50%;
				 }
			 }
		 }
		 
	 }
</style>
